<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="80px" label-position="left">
			<el-form-item label="排序号">
				<el-input-number v-model="form.sortNo" clearable placeholder="排序号"></el-input-number>
			</el-form-item>
			<el-form-item label="目录名称" prop="titleName">
				<el-input v-model="form.titleName" clearable placeholder="目录名称" maxlength="40"></el-input>
			</el-form-item>
			<el-form-item label="管理人员" prop="fileManageUser">
				<select-user-dialog v-model:accountId="form.fileManageUser" :mode="true" :hideAllBtn="true"/>
			</el-form-item>
			<el-form-item label="创建人员" prop="fileCreateUser">
				<select-user-dialog v-model:accountId="form.fileCreateUser" :mode="true" :hideAllBtn="true"/>
			</el-form-item>
			<el-form-item label="目录说明" prop="remark">
				<el-input v-model="form.remark" clearable placeholder="分类说明" type="textarea" maxlength="300"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
import selectUserDialog from "@/views/module/selectUserDialog";
export default {
	emits: ['success', 'closed'],
	components: {
		selectUserDialog
	},
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '新增目录对话框',
				edit: '编辑目录对话框'
			},
			visible: false,
			isSaveing: false,
			form: {
				sortNo:'',
				itemId:'',
				sortId:"",
				titleName: "",
				fileManageUser:'',
				fileCreateUser:'',
				remark:'',
			},
			rules: {
				titleName: [
					{required: true, message: '请输入目录名称'}
				]
			},
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode='add'){
			this.mode = mode;
			this.visible = true;
			return this;
		},
		//表单提交方法
		submit(){
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res
					if(this.mode=="add")
					{
						res = await this.$API.file.fileMap.insertFileMapItem.post(this.form);
					}else
					{
						res = await this.$API.file.fileMap.updateFileMapItem.post(this.form);
					}
					this.isSaveing = false;
					if(res.code == 200){
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					}else{
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		//表单注入数据
		setData(data){
			this.form.sortNo = data.sortNo
			this.form.sortId = data.sortId
			this.form.itemId = data.itemId
			this.form.titleName = data.titleName
			this.form.fileManageUser = data.fileManageUser
			this.form.fileCreateUser = data.fileCreateUser
			this.form.remark = data.remark
		}
	}
}
</script>

<style>
</style>
